package hot;

public class ERBAQI {
    public static int findDuplicate(int[] nums) {
        int slow=0;
        int fast=0;
        while(true){
            slow=nums[slow];//slow=slow.next;
            fast=nums[nums[fast]];//fast=fast.next.next
            if(slow==fast){
                break;
            }
        }
        int head=0;
        while(slow!=head){
            slow=nums[slow];
            head=nums[head];
        }
        return head;

    }

    public static void main(String[] args) {
        int[] nums={1,3,4,2,2};
        int duplicate = findDuplicate(nums);
        System.out.println(duplicate);
    }
}
